package com.example.demo.controller;

import com.example.demo.pojo.*;
import com.example.demo.service.SwiperandfeedbackService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.relational.core.sql.In;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.thymeleaf.model.IModel;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @author yanglup
 * @create 2020-12-04 21:44
 */
@Controller
public class BackSwiperandfeedbackController {
    @Autowired
    SwiperandfeedbackService swiperandfeedbackService;

    /**查询轮播图*/
    @RequestMapping("/swiperdataback")
    public String swiperdataback(Model model) {
        List<Swiperdata> list = swiperandfeedbackService.swiperdataback();
        model.addAttribute("swiperdatabacks",list);
        Integer allnumber=swiperandfeedbackService.Swiperallnumber();
        model.addAttribute("allnumber",allnumber);
//        System.out.println(allnumber);
        return "Swiperlist";
    }

    /**轮播图1--跳转到add*/
    @RequestMapping("/Swiperaddback")
    public String Ordersadd(Model model){
        return "Swiperadd";
    }
    /**轮播图提交2--保存数据跳回list*/
    @PostMapping("/Swiperaddbacktijiao")//post
    public String Swiperaddbacktijiao(Model model, SwiperdataParamacc swiperdataParamacc){
        String image_src=swiperdataParamacc.getImage_src();
        String navigator_url=swiperdataParamacc.getNavigator_url();
        swiperandfeedbackService.Swiperaddbacktijiao(image_src,navigator_url);
        return "redirect:/swiperdataback";
    }

    /**跳转到修改页面*/
    @RequestMapping("/Swiperupdate")
    public String Swiperupdate(Model model, Integer swiperdata_id, HttpSession session){
//        System.out.println(swiperdata_id);
        //通过id查询
        Swiperdata swiperdata=swiperandfeedbackService.Swiperupdate(swiperdata_id);
        model.addAttribute("swiperdata",swiperdata);
        session.setAttribute("chuanruswiperdata_id",swiperdata_id);

        return "Swiperupdate";
    }
    /**订单提交2--保存数据跳回list*/
    @PostMapping("/Swiperupdatetijiao")//post
    public String Swiperupdatetijiao(Model model, Swiperdata swiperdata,HttpSession session){
        //传入进来的
        Integer swiperdata_id1= (Integer) session.getAttribute("chuanruswiperdata_id");
        //提交到数据库
        Integer swiperdata_id2=swiperdata.getSwiperdata_id();//要修改的
        String image_src=swiperdata.getImage_src();
        String navigator_url=swiperdata.getNavigator_url();
        swiperandfeedbackService.Swiperupdatetijiao(swiperdata_id1,swiperdata_id2,image_src,navigator_url);
        return "redirect:/swiperdataback";
    }

    /**删除轮播图*/
    @RequestMapping("/Swiperdelete")
    public String Swiperdelete(Integer swiperdata_id){
        swiperandfeedbackService.Swiperdelete(swiperdata_id);
        return "redirect:/swiperdataback";
    }

    /**通过id搜索轮播图*/
    @RequestMapping("/Swiperqueryid")
    public String Swiperqueryid(Integer swiperdata_id,Model model){
        List<Swiperdata> swiperdatalist=swiperandfeedbackService.Swiperqueryid(swiperdata_id);
        model.addAttribute("swiperdatalists",swiperdatalist);
        Integer allnumber=swiperandfeedbackService.Swiperqueryidnumber(swiperdata_id);
        model.addAttribute("allnumber",allnumber);
        return "Swiperlistquery";
    }

    /****************************************************反馈处理*********************************************************************************/
    @RequestMapping("/wxfeedbacklist")
    public String wxfeedbacklist(Model model, HttpServletRequest request) {
        Integer pageNo=request.getParameter("pageNo")==null?1:Integer.valueOf(request.getParameter("pageNo"));
        PageInfo<Feedbackchuandi> pageInfo=swiperandfeedbackService.wxfeedbacklist(pageNo,8);

        List<Feedbackchuandi> list=pageInfo.getList();
        model.addAttribute("wxfeedbacklists",list);
        model.addAttribute("pages",pageInfo.getPages());
        model.addAttribute("pageNo",pageInfo.getPageNum());
        model.addAttribute("pageSize",pageInfo.getPageSize());

        Integer allnumber=swiperandfeedbackService.wxfeedbacklistnumber();
        model.addAttribute("allnumber",allnumber);
        return "WXFeedbacklist";
    }
//    /**查询反馈列表*/
//    @RequestMapping("/wxfeedbacklist")
//    public String wxfeedbacklist(Model model) {
//        List<Feedbackchuandi> list = swiperandfeedbackService.wxfeedbacklist();
//        model.addAttribute("wxfeedbacklists",list);
//        Integer allnumber=swiperandfeedbackService.wxfeedbacklistnumber();
//        model.addAttribute("allnumber",allnumber);
//        System.out.println(allnumber);
//        return "WXFeedbacklist";
//    }

    /**查看反馈详情*/
    @RequestMapping("/WXFeedbackcheck")
    public String WXFeedbackcheck(Model model, Integer feedback_id){

        Feedbackchuandi feedbackchuandi=swiperandfeedbackService.WXFeedbackcheck(feedback_id);
        model.addAttribute("feedbackchuandi",feedbackchuandi);
        return "WXFeedbackcheck";
    }

    /**删除反馈信息*/
    @RequestMapping("/WXFeedbackdelete")
    public String WXFeedbackdelete(Model model, Integer feedback_id){
        System.out.println(feedback_id);
        swiperandfeedbackService.WXFeedbackdelete(feedback_id);
        return "redirect:/wxfeedbacklist";
    }

}
